#include "Camera.h"


//////////////////////////////////////////////////////////////////////////
Camera::Camera(void) : mPos(0.f,0.f,0.f), mTarget(0.f,0.f,0.f), mUp(0.f,0.f,0.f), mDirty(true)
{
}


//////////////////////////////////////////////////////////////////////////
Camera::~Camera(void)
{
}

//////////////////////////////////////////////////////////////////////////
void Camera::Init()
{
	mPos.Set(0,0,-5);
	//mTarget = mPos;
	//mTarget.LookAt(Vec3());
	mUp.Set(0,1,0);
	ComputeViewMat();
}

void Camera::ComputeViewMat()
{
	Vec3 tFront = mTarget - mPos;
	tFront.Normalize();
	Vec3 tUp = mUp;
	Vec3 tLeft = tUp.Cross(tFront);
	tLeft.Normalize();
	tUp = tFront.Cross(tLeft);

	mViewMatrix[0][0] = tLeft.X();		mViewMatrix[0][1] = tUp.X();	mViewMatrix[0][2] = tFront.X();	mViewMatrix[0][3] = mPos.X();
	mViewMatrix[1][0] = tLeft.Y();		mViewMatrix[1][1] = tUp.Y();	mViewMatrix[1][2] = tFront.Y();	mViewMatrix[1][3] = mPos.Y();
	mViewMatrix[2][0] = tLeft.Z();		mViewMatrix[2][1] = tUp.Z();	mViewMatrix[2][2] = tFront.Z();	mViewMatrix[2][3] = mPos.Z();
	mViewMatrix[3][0] = 0.0f;			mViewMatrix[3][1] = 0.0f;		mViewMatrix[3][2] = 0.0f;		mViewMatrix[3][3] = 1.0f;   
	
	//mViewMatrix[0][0] = tLeft.X();		mViewMatrix[1][0] = tUp.X();	mViewMatrix[2][0] = tFront.X();	mViewMatrix[3][0] = 0.0f;//mPos.X();
	//mViewMatrix[0][1] = tLeft.Y();		mViewMatrix[1][1] = tUp.Y();	mViewMatrix[2][1] = tFront.Y();	mViewMatrix[3][1] = 0.0f;//mPos.Y();
	//mViewMatrix[0][2] = tLeft.Z();		mViewMatrix[1][2] = tUp.Z();	mViewMatrix[2][2] = tFront.Z();	mViewMatrix[3][2] = 0.0f;//mPos.Z();
	//mViewMatrix[0][3] = 0.0f;			mViewMatrix[1][3] = 0.0f;		mViewMatrix[2][3] = 0.0f;		mViewMatrix[3][3] = 1.0f;   
	//mViewMatrix.SelfTranslate(mPos.X(),mPos.Y(),mPos.Z());

	mDirty = false;
}
